package org.test.web.context;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;


import org.apache.log4j.Logger;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.test.common.Context;
import org.test.myTree.AbstractTree.ITreeService;


public class EMContextLoaderListener extends ContextLoaderListener {
	private final Logger LOG = Logger.getLogger(this.getClass());

	@Override
	public void contextDestroyed(ServletContextEvent event) {
		super.contextDestroyed(event);
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
		super.contextInitialized(event);
		LOG.debug("Beginnig ContexLoaderListener......");
		//业务上的东西
		//这纯粹是为了方便 开发时写的,放到Context的静态
		ServletContext servletContext = event.getServletContext();
		Context.servletContext = servletContext;
		Context.webApplicationContext = WebApplicationContextUtils
				.getWebApplicationContext(servletContext);
		//都是业务上的东西
		ITreeService treeService = (ITreeService) WebApplicationContextUtils.
					getWebApplicationContext(servletContext).getBean("treeServiceImpl");
		treeService.updateTree();
		
	}


}
